package basic._03_优先队列;


import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * @author： YHSimon
 * @date： 2022-08-19 13:53
 */
public class Solution {
    public static void main(String[] args) {
        int[] nums={1,3,4,6,7234,645,7,64,1,3};

        PriorityQueue<Integer> queue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1-o2;
            }
        });

        for (int i = 0; i < 5; i++) {
            queue.add(nums[i]);
        }
        for(int i=5;i<nums.length;i++){
            if(nums[i]>queue.peek()){
                queue.remove();
                queue.add(nums[i]);
            }
        }

        while(!queue.isEmpty()){
            System.out.print(queue.remove()+" ");
        }
    }
}
